<!--搜索框组件 -->
<template>
  <!-- 检索 -->
  <div class="searchDetail">
    <SearchNav
      v-if="showSearchNav"
      :ctNavID="ctNavID"
      :showRange="range"
      :activeIndex="activeIndex"
      @changeTab="changeTab"
    ></SearchNav>
    <!-- 智能检索 -->
    <div class="search-box" v-if="activeIndex == 0">
      <!-- 智能检索 -->
      <div class="search-bar-box">
        <!-- 数据源 -->
        <span
          v-if="ctNavID == 'patent'"
          class="data-source"
          @click="openDataSource"
        >
          <i class="icon"></i>
        </span>
        <span v-else class="data-source">
          <i class="icon-grey"></i>
        </span>

        <!-- 检索框 -->
        <div class="search-bar">
          <div class="search-inp">
            <el-input
              v-model="searchTxt"
              type="text"
              clearable
              placeholder="请输入关键词"
              @input="handleInput"
              @focus="handleFocus"
              @blur="handleBlur"
              @keyup.enter.native="search({ ipi: 1 })"
            />
          </div>
        </div>
        <span class="search-btn" @click="search({ ipi: 1 })">
          <i class="icon iconfont icon-sousuo"></i>
        </span>

        <p class="tools">
          <span
            v-if="listOrAnalysisType !== 'analysis'"
            title="复制当前检索式"
            @click="handleCopyToClipboard"
            class="icon icon1 el-icon-document-copy"
          ></span>
        </p>
      </div>
      <div class="search-tips-box">
        <!-- 智能检索-检索提示 -->
        <SmartSearchTips
          v-if="activeIndex == 0 && showTips"
          :searchTxt="searchTxt"
          @chooseTips="chooseTips"
          @moreHistory="openMoreHistory"
        />
        <!-- 智能检索-检索提示 -->
        <ProfessionalSearchTips
          v-if="activeIndex == 2 && showTips"
          :searchTxt="searchTxt"
          @chooseTips="chooseTips"
          @chooseTips2="chooseTips2"
        />
      </div>
    </div>
    <!-- 高级检索-专利 -->
    <AdvancedSearchPatent v-show="ctNavID == 'patent' && activeIndex == 1" />
    <!-- 高级检索-文献 -->
    <AdvancedSearch
      :ctNavID="ctNavID"
      v-show="
        (ctNavID == 'paper' ||
          ctNavID == 'achieve' ||
          ctNavID == 'project' ||
          ctNavID == 'standard') &&
          activeIndex == 1
      "
    ></AdvancedSearch>
    <!-- 扩展检索 -->
    <ExtendSearch v-show="activeIndex == 2" :ctNavID="ctNavID" />
    <!-- 语义检索 -->
    <SemanticSearch
      v-show="activeIndex == 3"
      :ctNavID="ctNavID"
      :activeIndex="activeIndex"
    />
    <!-- 查新检索  暂时注释 不可删除!!!!!!!!!!! -->
    <!-- <NewSearch v-show="activeIndex == 4" @openDataSource="openDataSource" /> -->
    <!-- 无效检索 暂时注释 不可删除!!!!!!!!!!! -->
    <!-- <Invalid v-show="activeIndex == 5" @openDataSource="openDataSource" /> -->
    <div class="tools">
      <div class="all">
        <p v-show="totalTxt !== ''" class="total-txt">
          为您找到相关数据约&nbsp;<span>{{ totalTxt }}</span
          >&nbsp;条
        </p>
        <p v-show="totalTxt !== ''" class="time-consuming">
          检索耗时
          <span>{{ timeConsuming }}</span>
          ms
        </p>
        <p v-show="ctNavID == 'patent'" class="">
          <el-select
            class="familyFlag"
            v-model="familyFlag"
            placeholder="请选择"
            size="mini"
            @change="search"
          >
            <el-option
              v-for="item in familyFlagOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </p>
      </div>
      <!-- 二次检索 -->
      <template v-if="isAnalysis">
        <div v-show="showTwiceBox" class="twice-box">
          <p
            class="toggle"
            v-show="activeIndex == 0"
            @click="toggleTwice = !toggleTwice"
          >
            <span class="icon iconfont icon-ercijiansuo"></span>
            <span v-show="!toggleTwice" class="label">二次检索</span>
            <span v-show="toggleTwice" class="label2">收起</span>
          </p>
          <!-- <transition name="slide-fade"> -->
          <p v-show="toggleTwice" class="twice-inp">
            <el-input
              placeholder="在结果中搜索"
              v-model="twiceInp"
              @keyup.enter.native="twiceSearch"
              class="twice-elinp"
            />
            <span class="enter-btn" @click="twiceSearch">↵</span>
          </p>
          <p v-show="toggleTwice" class="twice-inp">
            <el-input
              placeholder="在结果中排除"
              v-model="twiceInpDel"
              @keyup.enter.native="twiceSearch"
              class="twice-elinp"
            />
            <span class="enter-btn" @click="twiceSearch">↵</span>
          </p>
          <!-- </transition> -->
        </div>
        <div v-show="!showTwiceBox" class="keywords">
          <span>二次检索：</span>
          <span class="txt">{{ twiceInp }}</span>
          <span class="txt"> {{ twiceInpDel }}</span>
          <span class="btn" @click="handleResetTwice">×</span>
        </div>
      </template>
    </div>
    <!-- 选择数据源 -->
    <DataSource ref="dataSource" />
    <!-- 历史记录 -->
    <SmartHistory ref="smartHistory" @chooseTips="chooseTips" />
  </div>
</template>

<script>
import { mapState } from "vuex";
import {
  numFormat,
  transENCountry,
  patentField,
  copyToClipboard,
  getYear
} from "@/utils/utils";
export default {
  props: {
    keyword: {
      type: String,
    },
    ctNavID: {
      type: String,
    },
    showSearchNav: {
      type: Boolean,
      default: true,
    },
    listOrAnalysisType: {
      type: String,
    },
  },
  data() {
    return {
      range: 0, // 控制SearchNav显示的数量
      activeIndex: 0, // 控制检索类型
      showTips: false, // 控制检索历史记录
      searchTxt: "", // 智能检索 输入框的值
      currentSq: "",
      isAnalysis: true,
      showTwiceBox: true,
      toggleTwice: false,
      twiceInp: "",
      twiceInpDel: "",
      dataSourceSq: "", // 选择数据源的检索式
      // 分页
      ipi: 1,
      ips: 10,
      total: 0,
      totalTxt: "",
      sort: [],
      parmAggs: [],
      timeConsuming: "",
      familyFlag: false,
      familyFlagOptions: [
        {
          value: false,
          label: "全部",
        },
        {
          value: 1,
          label: "同族合并",
        },
        {
          value: 2,
          label: "同专利合并",
        },
      ],
      params: {}, //接口请求入参全局对象
      screenArrData: [], //左侧选中的分面数据
      datatype: 1,
      leftMenuId: 0,
      shieldSq: "",
      startYear: "",
      endYear: ""
    };
  },
  computed: {
    ...mapState([
      "searchWord",
      "advancedSearchWord",
      "createSq",
      "analysisScreen",
      "analysisChooseScreen",
      "totalTxtSerch",
    ]),
  },
  beforeMount() {
    let { startYear, endYear } = getYear(10);
    this.startYear = String(startYear);
    this.endYear = String(endYear);
  },
  mounted() {
    this.searchTxt = this.searchWord;
    this.mountedFun();

    this.$Bus.$on("analysis_startYear", (val) => {
      this.startYear = val
    });
    this.$Bus.$on("analysis_endYear", (val) => {
      this.endYear = val
    });
    
  },
  watch: {
    // 监听各种文献库、成果库等变化
    ctNavID: {
      handler(newVal) {
        // console.log("------newVal", newVal);
        this.twiceInp = "";
        this.twiceInpDel = "";
        this.currentSq = "";
        this.activeIndex = 0;
        this.ipi = 1;
        this.ips = 10;
        this.sort = [];
        this.changeAggs(newVal);
        if (this.listOrAnalysisType !== "analysis") {
          // 非分析页面
          this.smartSearch = this.searchWord;
          this.searchTxt = this.searchWord;
          if (this.createSq) {
            this.dataSourceSq = this.createSq;
          }
        } else {
          // 分析页面
          this.beforeMountFun();
        }
      },
      immediate: true,
    },
    // vuex中的变化会引起该变化 除高级检索之外
    searchWord(nval, oldv) {
      if (nval !== oldv) {
        // console.log('252222');
        this.beforeMountFun();
      }
    },
    // vuex中的变化会引起该变化 高级检索
    advancedSearchWord() {
      // console.log(1, "advancedSearchWord");
      this.search({ipi:1});
    },
    createSq() {
      let str = this.createSq;
      this.dataSourceSq = str;
      // console.log(2, "createSq");
      this.search();
    },
    //左侧分面数据
    analysisScreen(nval, oldv) {
      this.leftMenuId = nval.item_id;
      // console.log(3, "analysisScreen");
      this.search();
    },
    //检索结果条数
    totalTxtSerch(nval, oldv) {
      this.totalTxt = nval;
      this.totalTxt = nval && numFormat(nval);
    },

    analysisChooseScreen() {
      // console.log(4, "analysisChooseScreen");
      this.search();
    },
    // 监听是否为分析 分析没有二次检索
    listOrAnalysisType: {
      handler(nrwVal) {
        this.isAnalysis = nrwVal !== "analysis";
      },
      immediate: true,
    },
  },
  methods: {
    changeAggs(newVal) {
      if (newVal == "patent") {
        this.parmAggs = [
          { field: "nd", type: "keyword" },
          { field: "na", type: "keyword" },
          { field: "apd", type: "keyword" },
          { field: "isd", type: "keyword" },
          { field: "lss", type: "keyword" },
          { field: "an", type: "keyword" },
          { field: "ann", type: "keyword" },
          { field: "in", type: "keyword" },
          { field: "ipcm", type: "keyword" },
          {
            field: "j",
            type: "keyword",
            ranges: [
              { from: 90, to: 100 },
              { from: 80, to: 90 },
              { from: 70, to: 80 },
              { from: 60, to: 70 },
              { from: 50, to: 60 },
              { from: 30, to: 50 },
              { from: 0, to: 30 },
            ],
          },
          { field: "prir.country", type: "keyword" },
        ]; //根据分面类型查询分面数据 专利单独处理 单独调用接口获取
        this.range = 6;
      } else if (newVal == "paper") {
        this.range = 4;
        this.parmAggs = [
          //根据分面类型查询分面数据
          { field: "article_year", type: "date" },
          { field: "from_publication", type: "keyword" },
          { field: "country", type: "keyword" },
          { field: "org", type: "keyword" },
          { field: "author", type: "keyword" },
          { field: "keyword", type: "keyword" },
        ];
      } else if (newVal == "achieve") {
        this.range = 0;
        this.parmAggs = [
          //根据分面类型查询分面数据
          // { field: "achievement_type", type: "keyword" },
          // { field: "achievement_stage", type: "keyword" },
          // { field: "promotion_way", type: "keyword" },
          // { field: "achievement_field", type: "keyword" },
          // { field: "application_status", type: "keyword" },
          // { field: "registered_date", type: "date" },
          {
            field: "achievement_type",
            type: "keyword",
          },
          {
            field: "achievement_stage",
            type: "keyword",
          },
          {
            field: "promotion_way",
            type: "keyword",
          },
          {
            field: "achievement_field",
            type: "keyword",
          },
          {
            field: "application_status",
            type: "keyword",
          },
          {
            field: "registered_date",
            type: "date",
          },
          {
            field: "assess_format",
            type: "keyword",
          },
          {
            field: "achievement_industry",
            type: "keyword",
          },
          {
            field: "keywords",
            type: "keyword",
          },
          {
            field: "achievement_institution",
            type: "keyword",
          },
        ];
      } else if (newVal == "project") {
        this.range = 2;
        this.parmAggs = [
          //根据分面类型查询分面数据
          { field: "project_country", type: "keyword" },
          { field: "begin_year", type: "keyword" },
          { field: "fund_inst", type: "keyword" },
          { field: "support_inst", type: "keyword" },
        ];
      } else if (newVal == "standard") {
        this.range = 0;
        this.parmAggs = [
          //根据分面类型查询分面数据
          // { field: "issue_date", type: "keyword" },
          // { field: "kind", type: "keyword" },
          // { field: "status", type: "keyword" },
          {
            field: "issue_date",
            type: "keyword",
          },
          {
            field: "imp_date",
            type: "keyword",
          },
          {
            field: "kind",
            type: "keyword",
          },
          {
            field: "status",
            type: "keyword",
          },
          {
            field: "category",
            type: "keyword",
          },
          {
            field: "in_class",
            type: "keyword",
          },
          {
            field: "zh_class",
            type: "keyword",
          },
          {
            field: "industry",
            type: "keyword",
          },
          {
            field: "type",
            type: "keyword",
          },
        ];
      }
    },
    // 更改检索模式  activeIndex：0 智能检索 1 高级检索 2 专业检索 3 语义检索 4 查新检索 5 无效检索
    changeTab(value) {
      this.activeIndex = Number(value);
    },
    //初始化 处理默认搜索关键词
    beforeMountFun() {
      let sq = this.searchWord;
      if (this.createSq !== "") {
        let str = this.createSq;
        this.dataSourceSq = str;
      }
      if (sq && sq !== "") {
        this.searchTxt = sq;
      }
      // console.log(5, "beforeMountFun");
      this.search();
    },
    //增加监听事件，
    mountedFun() {
      // 列表-分页
      this.$Bus.$on("currentPage", (val) => {
        this.ipi = val;
        // console.log(6, "currentPage");
        this.search();
      });
      //列表-分页
      this.$Bus.$on("pageSize", (val) => {
        this.ips = val;
        // console.log(7, "pageSize");
        this.search();
      });
      // 列表-排序
      this.$Bus.$on("changeSort", (list) => {
        this.handleBus("sort", list);
      });
      // 列表-左侧筛选项
      this.$Bus.$on("screenArr", (list) => {
        this.screenArrData = list;
        // console.log(8, "screenArr");
        this.search({ipi:1});
      });
      // 屏蔽
      this.$Bus.$on("shield", (param) => {
        this.shieldSq = param.sq;
        this.search();
      });
    },
    //处理父组件传入参数 处理为入参要求数据格式
    handleBus(key, list) {
      this[key] = Array.isArray(list) ? list : [];
      this.ipi = 1;
      // console.log(9, "handleBus");
      this.search();
    },
    //处理分面数据，将选中的分面数据赋值给 this.params["eSearch"]
    handleScreenArrData(list) {
      let str = "";
      list.map((it, index) => {
        let label = `"${it.label}"`;
        // if (it.item.id == "ipcm") {
        //   label = `"${label}"`
        // }
        // 避免最后一位出现 AND
        if (index === list.length - 1) {
          if (this.ctNavID == "paper") {
            str = str + it.item.id + "=" + label;
          } else {
            str = str + it.item.id + "=" + label;
          }
        } else {
          if (this.ctNavID == "paper") {
            str = str + it.item.id + "=" + label + " AND ";
          } else {
            str = str + it.item.id + "=" + label + " AND ";
          }
        }
      });
      this.params["eSearch"] = str;
    },

    //搜索事件
    async search(ops = { str: "", ipi: "", filter: {} }) {
      console.log(">>>>>>>>触发search事件>>>>>>>>");
      this.changeAggs(this.ctNavID);
      this.$Bus.$emit("beginSearch", 1);
      this.$store.commit("setSearchWord", this.searchTxt);
      this.showTips = false;
      let addTxt = this.searchTxt;
      if (ops.ipi == 1) {
        this.twiceInp = "";
        this.twiceInpDel = "";
        this.showTwiceBox = true;
        this.toggleTwice = false;
        this.ipi = 1;
        this.$Bus.$emit("resetPageSize", 1);
      }
      if (ops.str && ops.str !== "") {
        addTxt += ops.str;
      } else if (
        this.dataSourceSq !== "" &&
        this.dataSourceSq !== ops.str &&
        this.ctNavID == "patent"
      ) {
        addTxt = addTxt + " and (" + this.dataSourceSq + ")";
      }
      // 二次检索
      if (this.twiceInp !== "") {
        let isNeedA = patentField(this.twiceInp.split("/")[0]);
        addTxt =
          "(" +
          addTxt +
          ")" +
          " AND " +
          (isNeedA ? this.twiceInp : "A/" + this.twiceInp);
      }
      if (this.twiceInpDel != "") {
        // twiceInpDel
        addTxt += ` and (not A/${this.twiceInpDel})`;
      }
      let newSearchTxt = addTxt; //esearch 用
      let newKeyWorld = this.searchTxt; //专业检索 语义检索用

      // 专利库
      if (this.ctNavID == "patent") {
        localStorage.setItem("familyFlag", this.familyFlag);
        if (this.familyFlag == 1) {
          this.params["familyFlag"] = true; // 同族合并
          this.params["tzzlhb"] = false; // 同专利合并
        } else if (this.familyFlag == 2) {
          this.params["tzzlhb"] = true; // 同专利合并
          this.params["familyFlag"] = false; // 同族合并
        } else {
          this.params["tzzlhb"] = false; // 同专利合并
          this.params["familyFlag"] = false; // 同族合并
        }
        // this.params["familyFlag"] = this.familyFlag; // 同族合并
        this.params["rSearch"] = ""; //清除语义检索数据
        this.params["smartSearch"] = ""; //清除智能检索数据
        let sq = "";
        if (this.activeIndex == 0) {
          sq = newSearchTxt + this.shieldSq;
        } else if (this.activeIndex == 1) {
          sq = this.advancedSearchWord + this.shieldSq;
        } else {
          sq = newKeyWorld + this.shieldSq;
        }

        this.handleScreenArrData(this.screenArrData);
        // 判断是否需要拼接左侧分面数据，不可以增加多余 AND 符号
        this.params["eSearch"] =
          sq && this.params["eSearch"]
            ? sq + " AND " + this.params["eSearch"]
            : this.params["eSearch"] || sq;
      }
      // 其他库
      else {
        // 智能检索
        if (this.activeIndex == 0) {
          this.params["rSearch"] = ""; //清除语义检索数据
          this.params["smartSearch"] = newSearchTxt + this.shieldSq; //清除智能检索数据
          this.params["eSearch"] = "";
          this.handleScreenArrData(this.screenArrData);
        }
        // 高级检索
        else if (this.activeIndex == 1) {
          this.params["smartSearch"] = "";
          this.params["rSearch"] = "";
          this.params["eSearch"] = ""; //清除高级检索数据
          this.handleScreenArrData(this.screenArrData);
          this.params["eSearch"] = this.params["eSearch"]
            ? this.params["eSearch"] +
              " AND " +
              this.advancedSearchWord +
              this.shieldSq
            : this.advancedSearchWord + this.shieldSq;
        }
        // 扩展检索
        else if (this.activeIndex == 2) {
          this.params["smartSearch"] = ""; //清除智能检索数据
          this.params["rSearch"] = ""; //清除语义检索数据
          this.params["eSearch"] = ""; //清除高级检索数据
          this.handleScreenArrData(this.screenArrData);
          this.params["eSearch"] = this.params["eSearch"]
            ? this.params["eSearch"] + " AND " + newSearchTxt + this.shieldSq
            : newSearchTxt + this.shieldSq;
        }
        // 语义检索
        else if (this.activeIndex == 3) {
          this.params["smartSearch"] = ""; //清除智能检索数据
          this.params["eSearch"] = ""; //清除高级检索数据
          this.handleScreenArrData(this.screenArrData);
          this.params["rSearch"] = newKeyWorld + this.shieldSq;
        }
        // 查新检索
        else if (this.activeIndex == 4 || this.activeIndex == 5) {
          this.params["smartSearch"] = ""; //清除智能检索数据
          this.params["rSearch"] = ""; //清除语义检索数据
          this.params["eSearch"] = ""; //清除高级检索数据
          this.params["eSearch"] = newKeyWorld + this.shieldSq;
        }
      }
      if (this.shieldSq && this.activeIndex == 0) {
        if (this.ctNavID == "patent") {
          this.searchTxt = this.params["eSearch"];
        } else {
          this.searchTxt = this.params["smartSearch"];
        }
      }
      // 如果是分析图表
      if (this.listOrAnalysisType == "analysis") {
        // console.log("ops", ops);
        // console.log("this.analysisChooseScreen", this.analysisChooseScreen);
        this.params["smartSearch"] = ""; //清除智能检索数据
        this.params["rSearch"] = ""; //清除语义检索数据
        let datefield = this.analysisScreen.datefield;
        this.params["eSearch"] =
          newSearchTxt +
          " AND " +
          `${datefield}>=${this.startYear}-01-01 AND ${datefield}<=${this.endYear}-12-31`;
        this.parmAggs = this.analysisScreen.aggs; // 图表-左侧筛选项
        if (this.parmAggs) {
          this.parmAggs[0]["size"] =
            this.parmAggs[0]["field"] == "keywords" ? 100 : 10;
          //判断是否为论文二位分析 拦截请求数量
          if (
            this.parmAggs[0]?.parameters?.search_type == "2DAnalysis" &&
            this.parmAggs[0]?.parameters?.two_d_parm ==
              "authors.org.keyword-keywords.keyword-20"
          ) {
            this.parmAggs[0].parameters.two_d_parm =
              "authors.org.keyword-keywords.keyword-5";
          }
        }
        if (this.ctNavID === "paper") {
          this.params["eSearch"] =
            newSearchTxt +
            // ` AND ${datefield}>=${this.analysisChooseScreen.startYear} AND ${datefield}<=${this.analysisChooseScreen.endYear}`;
            ` AND ${datefield}>=2014 AND ${datefield}<=2024`;
        } else if (this.ctNavID === "achieve") {
          this.params["eSearch"] =
            newSearchTxt +
            ` AND registered_date>=${this.analysisChooseScreen.startYear}-01-01 AND registered_date<=${this.analysisChooseScreen.endYear}-01-01`;
        } else if (this.ctNavID === "project") {
          this.params["eSearch"] =
            newSearchTxt +
            ` AND begin_date>=${this.analysisChooseScreen.startYear}-01-01 AND end_date<=${this.analysisChooseScreen.endYear}-01-01`;
        } else if (this.ctNavID === "standard") {
          this.params["eSearch"] =
            newSearchTxt +
            ` AND issue_date>=${this.analysisChooseScreen.startYear}-01-01 AND issue_date<=${this.analysisChooseScreen.endYear}-01-01`;
        }
        // 过滤不公告发明人
        if (
          this.leftMenuId == 103000 ||
          this.leftMenuId == 401000 ||
          this.leftMenuId == 402000 ||
          this.leftMenuId == 602000
        ) {
          this.params["eSearch"] =
            this.params["eSearch"] + " AND in1!=不公告发明人";
        }
      }
      let ips = this.listOrAnalysisType == "analysis" ? 0 : this.ips; //区分查询列表还是查询聚合数据
      if (this.leftMenuId == 101000) {
        ips = 1;
      }
      //词云单独增加字段psskey = ’1‘
      if (
        (this.leftMenuId == 700000 && this.ctNavID == "patent") ||
        (this.ctNavID == "paper" && this.leftMenuId == 6000000)
      ) {
        this.params["psskey"] = "1";
      } else {
        this.params["psskey"] = "";
      }
      this.params = {
        ...this.params,
        dbid: this.ctNavID,
        ipi: Number(this.ipi),
        ips: ips,
        // ips: 1, //区分查询列表还是查询聚合数据
        sort: this.ctNavID == "paper" ? this.sort[0] : this.sort,
        aggs: this.parmAggs,
      };
      // console.log(33, this.leftMenuId)
      if (this.leftMenuId == "201000" || this.leftMenuId == "202000") {
        this.params["other"] = true;
      } else {
        delete this.params["other"];
      }
      if (this.leftMenuId == "601000") {
        this.params["size"] = 10;
        delete this.params["aggs"];
      }
      if (this.leftMenuId == "301000") {
        this.params["translate"] = true;
      } else {
        delete this.params["translate"];
      }
      console.log("params", this.params);
      // 耗时
      let timeConsuming = moment();
      this.$Bus.$emit("dcData", {});
      // console.log(">>>>>>>>触发search事件 this.params>>>>>>>>", this.params);

      /**
       * 1、图表分析单独处理的接口包含 ：专利趋势分析 /
       * 2、根据不同的菜单调用不同的接口，参数也不同
       */

      let url = "";
      // console.log("this.leftMenuId", this.leftMenuId);
      switch (this.leftMenuId) {
        case 101000:
          url = this.$Url.search.patentAggsTrends;
          break;
        case 104000:
          url = this.$Url.search.legaltrendsTrends;
          break;
        case 601000:
          url = this.$Url.search.anpartnershipTrends;
          break;
        case 105000:
          url = this.$Url.search.countryTrends;
          break;
        case 302000:
          url = this.$Url.search.antypeTrends;
          break;
        default:
          url = this.$Url.search.commonSearch;
          break;
      }
      this.$post(url, this.params)
        .then((res) => {
          this.shieldSq = "";
          this.$Bus.$emit("beginSearch", 2);
          let data = res.data;
          let initData = {};
          if (data) {
            if (data?.result?.length == 0) {
              this.emptyText = "无法找到你所查询的内容，换个关键词试试";
            }
            timeConsuming = numFormat(moment().diff(timeConsuming));
            this.timeConsuming = timeConsuming;
            this.total = data.total;
            this.totalTxt = data.total && numFormat(data.total);
            initData = data || {};
            // this.$store.commit("setSearchWord", this.searchTxt);
            if (data.reviewWord && this.activeIndex == 0) {
              this.searchTxt = data.reviewWord;
            }
          } else {
            initData = {};
            this.total = 0;
            this.totalTxt = "";
            // this.emptyText = "无法找到你所查询的内容，换个关键词试试";
          }
          if (this.listOrAnalysisType == "analysis") {
            initData = {
              ...initData,
              datatype: this.analysisScreen.datatype,
            };
          }
          if (this.ctNavID == "paper") {
            initData.pageNum = this.params.ipi - 1;
          }
          this.$Bus.$emit("dcData", initData);
          //分面数据
          this.$Bus.$emit("facetData", data.aggs);
        })
        .catch((err) => {
          this.shieldSq = "";
          // this.emptyText = "无法找到你所查询的内容，换个关键词试试";
        });
    },
    // 获取焦点
    handleFocus() {
      this.showTips = true;
    },
    // 失焦
    handleBlur() {
      setTimeout(() => {
        this.showTips = false;
      }, 250);
    },
    // 输入
    handleInput() {
      if (this.searchTxt === "") {
        return;
      }
      this.showTips = true;
    },

    // 选择tips
    chooseTips({ key }) {
      this.searchTxt = key || "";
      this.search({ ipi: 1 });
    },
    chooseTips2({ item, isSearch }) {
      // 截取示例后面的检索式
      let str = item.value;
      let dom = document.createElement("span");
      dom.innerHTML = str;
      document.body.append(dom);
      let txt = dom.innerText;
      let arr = txt.split("示例：");
      document.body.removeChild(dom);
      this.searchTxt = arr[arr.length - 1];
      if (isSearch) this.search();
    },
    openMoreHistory() {
      this.$refs.smartHistory.init();
    },
    // 选择数据源
    openDataSource() {
      this.$refs.dataSource.init();
    },
    // 二次检索
    twiceSearch() {
      if (this.twiceInp == "" && this.twiceInpDel == "") {
        this.$message({
          type: "warning",
          message: "内容不能为空！",
          duration: 1000,
        });
        return;
      }
      // TODO twiceInpDel
      // this.$store.commit("setSecondeSq", this.twiceInp);
      // sessionStorage.setItem("secondeSq", this.twiceInp); //存入sessage 供二次检索使用
      // console.log(13, "twiceSearch");

      this.search();
      this.showTwiceBox = false;
    },

    handleResetTwice() {
      this.twiceInp = "";
      this.twiceInpDel = "";
      this.showTwiceBox = true;
      // this.$store.commit("setSecondeSq", this.twiceInp);
      // sessionStorage.setItem("secondeSq", this.twiceInp); //存入sessage 供二次检索使用
      // console.log(14, "handleResetTwice");
      this.search();
    },
    // 复制到剪切板
    handleCopyToClipboard() {
      if (copyToClipboard(this.searchTxt)) {
        this.$message({
          type: "success",
          duration: 1500,
          message: "复制成功！",
        });
      } else {
        this.$message({
          type: "error",
          duration: 1500,
          message: "复制失败！",
        });
      }
    },
  },

  beforeDestroy() {
    this.$Bus.$off("data");
    this.$Bus.$off("pageSize");
    this.$Bus.$off("currentPage");
    // this.$Bus.$off("changeSort");
    this.$Bus.$off("screenArr");
    this.$Bus.$off("analysis_startYear");
    this.$Bus.$off("analysis_endYear");
  },
  components: {
    SearchNav: () =>
      import("@/views/modules/DataCenter/child/base/SearchNav.vue"),
    DataSource: () =>
      import("@/views/modules/DataCenter/components/DataSource"),
    SmartSearchTips: () =>
      import("@/views/modules/DataCenter/components/way/SmartSearchTips"),
    ProfessionalSearchTips: () =>
      import(
        "@/views/modules/DataCenter/components/way/ProfessionalSearchTips"
      ),
    AdvancedSearchPatent: () =>
      import("@/views/modules/DataCenter/components/way/AdvancedSearchPatent"),
    AdvancedSearch: () =>
      import("@/views/modules/DataCenter/components/way/AdvancedSearch.vue"),
    SemanticSearch: () =>
      import("@/views/modules/DataCenter/components/way/SemanticSearch"),
    ExtendSearch: () =>
      import("@/views/modules/DataCenter/components/way/extendSearch"),
    NewSearch: () =>
      import("@/views/modules/DataCenter/components/way/NewSearch"),
    SmartHistory: () =>
      import("@/views/modules/DataCenter/components/way/smartHistory"),
    Invalid: () => import("@/views/modules/DataCenter/components/way/Invalid"),
  },
};
</script>

<style lang="scss" scoped>
.searchDetail {
  width: 100%;
  .search-box {
    position: relative;
    // display: inline-flex;
    // flex-wrap: wrap;
    width: 100%;
    height: 40px;
    // border: 1px solid $mainColor;
    border-radius: 20px;
    margin-bottom: 10px;
    .search-tab {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      margin-left: 12px;
      p {
        position: relative;
        width: 96px;
        line-height: 40px;
        margin: 0;
        text-align: center;
        font-size: 16px;
        color: $color10;
        cursor: pointer;
        &.active {
          font-weight: 600;
          color: $mainColor;
        }
        &:after {
          position: absolute;
          top: 50%;
          right: 0;
          width: 1px;
          height: 20px;
          margin-top: -10px;
          background-color: $color143;
          content: "";
        }
        &:last-of-type {
          &:after {
            content: none;
          }
        }
      }
    }
    .search-bar-box {
      position: relative;
      // border: 2px solid $mainColor;
      border-radius: 30px;
      display: flex;
      .data-source {
        position: absolute;
        top: 0;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 80px;
        height: 100%;
        line-height: 56px;
        text-align: center;
        cursor: pointer;
        &:after {
          position: absolute;
          top: 50%;
          right: 0;
          width: 1px;
          height: 20px;
          margin-top: -10px;
          background-color: $color148;
          content: "";
        }
        .icon {
          display: inline-block;
          width: 20px;
          height: 20px;
          color: $color141;
          background: url(../../../../../assets/img/PS/data-source-icon.png)
            no-repeat center center;
          background-size: auto 100%;
        }
        .icon-grey {
          display: inline-block;
          width: 20px;
          height: 20px;
          color: $color141;
          background: url(../../../../../assets/img/PS/data-source-icon-grey.png)
            no-repeat center center;
          background-size: auto 100%;
        }
      }
      .search-bar {
        display: block;
        padding-left: 80px;
        padding-right: 86px;
        height: 50px;
        border-radius: 30px;
        background-color: $color2;
        .search-inp {
          flex: 1;
          line-height: 48px;
          ::v-deep {
            .el-input {
              display: block;
            }
            .el-input__inner {
              border: 0;
            }
          }
          input {
            width: 100%;
            line-height: 40px;
            font-size: 14px;
            border: none;
            outline: none;
          }
        }
      }
      .search-btn {
        position: absolute;
        top: 0px;
        right: 80px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 86px;
        height: 50px;
        border-top-right-radius: 30px;
        border-bottom-right-radius: 30px;
        text-align: center;
        cursor: pointer;
        background-color: $mainColor;
        .icon {
          width: 40px;
          height: 40px;
          line-height: 40px;
          font-size: 28px;
          color: $color2;
        }
      }
      // .search-tips-box {
      //   position: relative;
      // }
    }

    .data-source {
      position: relative;
      display: flex;
      width: 48px;
      height: 100%;
      line-height: 40px;
      border-top-left-radius: 30px;
      border-bottom-left-radius: 30px;
      border-left: 2px solid $mainColor;
      border-top: 2px solid $mainColor;
      border-bottom: 2px solid $mainColor;
      text-align: center;
      background-color: #fff;
      cursor: pointer;
      &:after {
        position: absolute;
        top: 50%;
        right: 0;
        width: 1px;
        height: 20px;
        margin-top: -10px;
        background-color: $color142;
        content: "";
      }
      .icon {
        position: relative;
        padding-left: 12px;
        padding-right: 7px;
        font-size: 24px;
        color: $mainColor;
      }
    }
    .search-bar {
      flex: 1;
      display: inline-flex;
      align-items: center;
      flex-wrap: wrap;
      height: 40px;
      border-top: 2px solid $mainColor;
      border-bottom: 2px solid $mainColor;
      background-color: #fff;
      .search-inp {
        position: relative;
        flex: 1;
        height: 40px;
        padding-right: 10px;
        ::v-deep {
          .el-input__inner {
            height: 38px;
            border: 0;
          }
        }
      }
    }
    .tools {
      position: relative;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 80px;
      line-height: 100%;
      padding: 1px 10px;
      font-weight: normal;
      .icon {
        display: inline-block;
        width: 18px;
        text-align: center;
        font-size: 18px;
        color: $mainColor;
        cursor: pointer;
        &:hover {
          font-weight: 400;
        }
        &.icon1 {
          // padding-top: 10px;
        }
      }
    }
  }
  .search-tips-box {
    position: relative;
    max-height: 380px;
  }
  > .tools {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 45px;
    .all {
      font-size: 12px;
      color: $color6;
      p {
        display: inline-block;
        &.total-txt {
          span {
            color: $mainColor;
          }
        }
        &.time-consuming {
          display: inline-block;
          margin-left: 10px;
          span {
            display: inline-block;
            margin: 0 4px;
            color: $mainColor;
          }
        }
      }
      .familyFlag {
        margin-left: 50px;
        width: 100px;
      }
    }
    .twice-box {
      display: inline-flex;
      align-items: center;
      font-size: 12px;
      overflow: hidden;
      padding: 10px 0;
      .toggle {
        display: inline-flex;
        align-items: center;
        cursor: pointer;
        .icon {
          font-size: 20px;
          vertical-align: middle;
          color: $mainColor;
        }
        .icon-ercijiansuo {
          position: relative;
          top: -3px;
        }
        .label {
          margin-left: 6px;
          margin-right: 18px;
          vertical-align: middle;
          color: $color6;
        }
        .label2 {
          vertical-align: middle;
          color: $color37;
        }
      }
      .twice-inp {
        position: relative;
        width: 220px;
        height: 30px;
        border: 1px solid $color37;
        border-radius: 15px;
        margin-left: 10px;
        background-color: #fff;
        .twice-elinp {
          width: 100%;
          padding-right: 30px;
          border: none;
          border-radius: 15px;
          box-sizing: border-box;
          margin-left: 0;
          background-color: transparent;
          overflow: hidden;
        }
      }
      .enter-btn {
        position: absolute;
        top: 0;
        right: 0;
        width: 30px;
        line-height: 26px;
        text-align: center;
        font-weight: 600;
        font-size: 20px;
        color: $color37;
        cursor: pointer;
      }
      &:hover {
        .icon {
          color: $mainColor;
        }
        .enter-btn {
          color: $mainColor;
        }
      }
    }
    .keywords {
      display: flex;
      align-items: center;
      height: 30px;
      padding: 0 13px 0 15px;
      border: 1px solid $color37;
      border-radius: 3px;
      box-sizing: border-box;
      font-size: 12px;
      .txt {
        margin-right: 14px;
        color: $mainColor;
      }
      .btn {
        font-size: 18px;
        font-weight: 600;
        color: $mainColor;
        cursor: pointer;
      }
    }
  }
}
</style>
